export default {
  // 开启命名空间
  namespaced: true,
  // 储存数据
  state: {
    name: 'joker',
    age: 17,
    skill: 'jump'
  },
  //   修改state的状态，同步操作
  mutations: {
    setSkill (state, newSkill) {
      state.skill = newSkill
    },
    setName (state, newName) {
      state.name = newName
    }
  },
  //   state的计算属性
  getters: {
    isAdult (state) {
      return state.age >= 18 ? '成年' : '为成年'
    }
  },
  //   修改state的状态，异步操作
  actions: {
    setNameAsync (context, newName) {
      setTimeout(() => {
        context.commit('setName', newName)
      }, 1000)
    }
  }
}
